import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yinsh
 * Date: 2025-01-21
 * Time: 22:26
 */
public class MinStack {
    Stack<Integer> stack1 = new Stack<>();
    Stack<Integer> stack2 = new Stack<>();
    public MinStack() {

    }

    public void push(int val) {
        if (stack1.empty()&&stack2.empty()) {
            stack2.push(val);
            stack1.push(val);
        }else {
            stack1.push(val);
            if (val <= stack2.peek()) {
                stack2.push(val);
            }
        }
    }

    public void pop() {
        if (stack1.peek() == (stack2.peek()) ) {
            stack2.pop();
        }
        stack1.pop();

    }

    public int top() {
        return stack1.peek();
    }

    public int getMin() {
        return stack2.peek();
    }
}


